package com.bt.lms.ui.page.teaching.arrange;

import com.bt.lms.ui.action.teaching.arrange.PageAddTeachingArrangeCancelBtnAction;
import com.bt.lms.ui.action.teaching.arrange.PageAddTeachingArrangeSaveBtnAction;
import com.bt.lms.ui.action.teaching.arrange.PageAddTeachingArrangeStartCourseBtnAction;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.ObservableList;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

/**
 * 批量新增教学教学安排界面
 */
public class PageAddTeachingArrange extends VBox {

    /**
     * 新增教学安排界面宽度
     */
    private double preWidth = 1280;
    /**
     * 新增教学安排界面高
     */
    private double preHeight = 800;

    public PageAddTeachingArrange() {

        this.setPadding(new Insets(5));
        this.setSpacing(20);
        this.setPrefSize(preWidth, preHeight);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //新增教学安排横向盒子
        HBox addTeachingArrangeHBox = new HBox();
        initEnrollStuInfoHBox(addTeachingArrangeHBox);
        //网格盒子
        VBox netVBox = new VBox();
        initNetVBox(netVBox);
        //底部盒子
        HBox bottomHBox = new HBox();
        initBottomHBox(bottomHBox);


        //滚动条盒子
        VBox scrollPaneVBox = new VBox();
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setContent(scrollPaneVBox);
        scrollPane.setPrefSize(preWidth, preHeight);


        scrollPaneVBox.getChildren().addAll(topHBox, addTeachingArrangeHBox, netVBox, bottomHBox);

        ObservableList<Node> children = this.getChildren();
        children.addAll(scrollPane);


    }

    /**
     * 底部盒子
     *
     * @param bottomHBox
     */
    private void initBottomHBox(HBox bottomHBox) {
        bottomHBox.setPadding(new Insets(10));
        bottomHBox.setSpacing(20);
        bottomHBox.setAlignment(Pos.CENTER);
        //保存按钮
        Button saveBtn = new Button("保存");
        BtnStyle.saveBtn(saveBtn);

        //保存按钮事件
        PageAddTeachingArrangeSaveBtnAction pageAddTeachingArrangeSaveBtnAction = new PageAddTeachingArrangeSaveBtnAction();
        saveBtn.setOnAction(pageAddTeachingArrangeSaveBtnAction);
        saveBtn.setCursor(Cursor.HAND);
        pageAddTeachingArrangeSaveBtnAction.setPageAddTeachingArrange(this);
        //保存并确认开课按钮
        Button startCourseBtn = new Button("保存并确认开课");
        BtnStyle.saveBtn(startCourseBtn);

        //保存按钮事件
        PageAddTeachingArrangeStartCourseBtnAction pageAddTeachingArrangeStartCourseBtnAction = new PageAddTeachingArrangeStartCourseBtnAction();
        startCourseBtn.setOnAction(pageAddTeachingArrangeStartCourseBtnAction);
        startCourseBtn.setCursor(Cursor.HAND);
        pageAddTeachingArrangeStartCourseBtnAction.setPageAddTeachingArrange(this);

        //取消按钮
        Button cancelBtn = new Button("取消");
        BtnStyle.cancelBtn(cancelBtn);
        ObservableList<Node> children = bottomHBox.getChildren();
        children.addAll(saveBtn, startCourseBtn, cancelBtn);
        //取消按钮事件
        PageAddTeachingArrangeCancelBtnAction pageAddTeachingArrangeCancelBtnAction = new PageAddTeachingArrangeCancelBtnAction();
        cancelBtn.setOnAction(pageAddTeachingArrangeCancelBtnAction);
        cancelBtn.setCursor(Cursor.HAND);
    }

    /**
     * 网格盒子
     *
     * @param netVBox
     */
    private void initNetVBox(VBox netVBox) {
        netVBox.setSpacing(20);
        netVBox.setPadding(new Insets(2, 2, 2, 20));
        //网格
        GridPane gridPane = new GridPane();
        gridPane.setHgap(15);
        gridPane.setVgap(20);

        //设置课程部分
        //标签
        Label setCourseLab = new Label("设置课程*");
        setCourseLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //文本框
        TextField setCourseTF = new TextField();
        setCourseTF.setId("setCourseTF");
        //选择按钮
        Button selectCourseBtn = new Button("选择");
        BtnStyle.cancelBtn(selectCourseBtn);
        selectCourseBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                selectCourseBtn.setCursor(Cursor.HAND);
            }
        });
        //弹出窗口事件
        selectCourseBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Stage stage = new Stage();
                stage.show();
            }
        });
        gridPane.add(setCourseLab, 0, 1);
        gridPane.add(setCourseTF, 1, 1);
        gridPane.add(selectCourseBtn, 2, 1);

        //设置教师部分
        //标签
        Label setTeacherLab = new Label("设置教师*");
        setTeacherLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //文本框
        TextField setTeacherTF = new TextField();
        setTeacherTF.setId("setTeacherTF");
        //选择按钮
        Button selectTeacherBtn = new Button("选择");
        BtnStyle.cancelBtn(selectTeacherBtn);
        selectTeacherBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                selectTeacherBtn.setCursor(Cursor.HAND);
            }
        });

        selectTeacherBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Stage stage = new Stage();
                stage.show();
            }
        });
        gridPane.add(setTeacherLab, 0, 2);
        gridPane.add(setTeacherTF, 1, 2);
        gridPane.add(selectTeacherBtn, 2, 2);

        //设置学员部分
        //设置学员标签
        Label setStuLab = new Label("设置学员*");
        setStuLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //详细文本框
        TextField detailTF = new TextField("招生计划A:A班(15/30");
        detailTF.setId("detailTF");
        //选择按钮
        Button selectClassBtn = new Button("选择");
        selectClassBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                selectClassBtn.setCursor(Cursor.HAND);
            }
        });

        //弹出窗口事件
        selectClassBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Stage stage = new Stage();
                stage.show();
            }
        });
        BtnStyle.cancelBtn(selectClassBtn);
        gridPane.add(setStuLab, 0, 3);
        gridPane.add(detailTF, 1, 3);
        gridPane.add(selectClassBtn, 2, 3);

//

        //教学方式部分
        //标签
        Label teachingWayLab = new Label("教学方式");
        teachingWayLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //下拉框
        ComboBox teachingWayCB = new ComboBox<>();
        teachingWayCB.getItems().add("面授学习");
        teachingWayCB.getItems().add("在线学习");
        teachingWayCB.getItems().add("混合式学习");
        teachingWayCB.setId("teachingWayCB");
        teachingWayCB.getSelectionModel().selectFirst();
        gridPane.add(teachingWayLab, 0, 4);
        gridPane.add(teachingWayCB, 1, 4);

        //开课时间部分
        //标签
        Label startCourseLab = new Label("开课时间*");
        startCourseLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //日期选择器
        DatePicker startCourseDP = new DatePicker();
        startCourseDP.setId("startCourseDP");
        gridPane.add(startCourseLab, 0, 5);
        gridPane.add(startCourseDP, 1, 5);

        //结课时间部分
        //标签
        Label finishCourseLab = new Label("结课时间*");
        finishCourseLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //日期选择器
        DatePicker finishCourseDP = new DatePicker();
        finishCourseDP.setId("finishCourseDP");
        gridPane.add(finishCourseLab, 0, 6);
        gridPane.add(finishCourseDP, 1, 6);

//        /

        //课程目标部分
        //标签
        Label courseAimLab = new Label("课程目标*");
        courseAimLab.setFont(Font.font(null, FontWeight.BOLD, null, 16));
        //文本域
        TextArea courseAimTA = new TextArea();
        courseAimTA.setId("courseAimTA");
        gridPane.add(courseAimLab, 0, 7);
        gridPane.add(courseAimTA, 1, 7);





        ObservableList<Node> children = netVBox.getChildren();
        children.addAll(gridPane);


    }

    /**
     * 新增教学安排横向盒子
     *
     * @param addTeachingArrangeHBox
     */
    private void initEnrollStuInfoHBox(HBox addTeachingArrangeHBox) {
        addTeachingArrangeHBox.setPadding(new Insets(2));
        //新增教学安排标签
        Label addTeachingArrangeLab = new Label("新增教学安排");
        //设置字体大小
        addTeachingArrangeLab.setFont(Font.font(null, FontWeight.BOLD, null, 22));
        addTeachingArrangeLab.setTextFill(Color.rgb(198, 0, 1));//字体颜色
        addTeachingArrangeHBox.getChildren().addAll(addTeachingArrangeLab);
    }

    /**
     * 顶部横向盒子
     *
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(2));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学安排>新增教学安排");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }


}
